package com.qyy.www_chatroom.controller;


import com.qyy.www_chatroom.mapper.FriendMapper;
import com.qyy.www_chatroom.model.Friend;
import com.qyy.www_chatroom.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("friend")
public class FriendController {

    @Autowired
    private FriendMapper friendMapper;


    @RequestMapping("friendList")
    public Object getFriendList(HttpServletRequest request){
        HttpSession session = request.getSession();
        if(session == null){
            System.out.println("getFriendList，session不存在");
            return new ArrayList<Friend>();
        }

        User user = (User)session.getAttribute("user");
        if(user == null){
            System.out.println("getFriendList，user不存在");
            return new ArrayList<Friend>();
        }
        List<Friend> friendList = friendMapper.selectFriendList(user.getUserId());
        return friendList;
    }

}
